<template>
  <a-form layout="horizontal" :form="form" class="form" style="width:99%;">
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="组织编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            v-decorator="[
              'orgCode',
              {rules: [{ required: false, message: '请输入组织编码', whitespace: true}]}
            ]"
            placeholder=""
          />
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="组织名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            placeholder=""
            v-decorator="[
              'orgName',
              {rules: [{ required: true, message: '请输入组织名称', whitespace: true}]}
            ]"/>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="上级ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            v-decorator="[
              'parentId',
              {rules: [{ required: false, message: '请输入上级组织ID', whitespace: true}]}
            ]"
            placeholder=""
          />
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="上级名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            v-decorator="[
              'parentName',
              {rules: [{ required: false, message: '请输入上级组织名称', whitespace: true}]}
            ]"
            placeholder=""
          />
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="组织类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-tree-select
            showSearch
            style="width: 100%"
            :dropdownStyle="{ maxHeight: '300px', overflow: 'auto' }"
            placeholder="请选择"
            allowClear
            treeDefaultExpandAll
            treeNodeFilterProp="title"
            :treeData="orgTypeSelectTreeData"
            v-decorator="[
              'orgType',
              {rules: [{ required: true, message: '请输入组织类型', whitespace: true}], initialValue: this.initData.areaCode}
            ]"
          >
          </a-tree-select>
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择"
            allowClear
            v-decorator="[
              'status',
              {rules: [{ required: true, message: '请输入状态', whitespace: true}], initialValue: this.initData.status}
            ]"
          >
            <a-select-option value="0">禁用</a-select-option>
            <a-select-option value="1">启用</a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="虚拟组织" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择"
            allowClear
            v-decorator="[
              'fictitious',
              {rules: [{ required: true, message: '请输入虚拟组织', whitespace: true}], initialValue: '0'}
            ]"
          >
            <a-select-option value="0">否</a-select-option>
            <a-select-option value="1">是</a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="树虚拟" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择"
            allowClear
            v-decorator="[
              'treeFlag',
              {rules: [{ required: true, message: '请输入树虚拟', whitespace: true}], initialValue: '0'}
            ]"
          >
            <a-select-option value="0">否</a-select-option>
            <a-select-option value="1">是</a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="行政区划" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-tree-select
            showSearch
            style="width: 100%"
            :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
            placeholder="请选择"
            allowClear
            treeDefaultExpandAll
            treeNodeFilterProp="title"
            :treeData="areaCodeSelectTreeData"
            v-decorator="[
              'areaCode',
              {rules: [{ required: false, message: '请输入所属行政区划', whitespace: true}], initialValue: this.initData.areaCode}
            ]"
          >
          </a-tree-select>
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="组织性质" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择"
            allowClear
            v-decorator="[
              'orgPro',
              {rules: [{ required: false, message: '请输入性质', whitespace: true}]}
            ]"
          >
            <a-select-option v-for="item in dictData.orgPro" :key="item.dictKey" :value="item.dictKey">{{ item.dictValue }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="主管单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-tree-select
            showSearch
            style="width: 100%"
            :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
            placeholder="请选择"
            allowClear
            treeDefaultExpandAll
            treeNodeFilterProp="title"
            :treeData="orgSelectTreeData"
            v-decorator="[
              'mainDeptId',
              {rules: [{ required: false, message: '请输入主管单位', whitespace: true}], initialValue: this.initData.areaCode}
            ]"
          >
          </a-tree-select>
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="科室标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择"
            allowClear
            v-decorator="[
              'insideFlag',
              {rules: [{ required: false, message: '请输入科室标识', whitespace: true}], initialValue: '0'}
            ]"
          >
            <a-select-option value="0">否</a-select-option>
            <a-select-option value="1">是</a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            placeholder=""
            v-decorator="[
              'contact',
              {rules: [{ required: false, message: '请输入联系人', whitespace: true}]}
            ]"/>
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="联系手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            placeholder=""
            v-decorator="[
              'cellphone',
              {rules: [{ required: false, message: '请输入联系手机', whitespace: true}]}
            ]"/>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            placeholder=""
            v-decorator="[
              'phone',
              {rules: [{ required: false, message: '请输入联系电话', whitespace: true}]}
            ]"/>
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="账号情况" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择"
            allowClear
            disabled
            v-decorator="[
              'hasAccount',
              {rules: [{ required: true, message: '请输入账号情况', whitespace: true}], initialValue: '0'}
            ]"
          >
            <a-select-option value="0">未生成</a-select-option>
            <a-select-option value="1">已生成</a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="12" :sm="24">
        <a-form-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number
            disabled
            style="width: 100%"
            v-decorator="[
              'orderNo',
              {rules: [{ type: 'number', required: false, message: '请输入排序', whitespace: true}]}
            ]"/>
        </a-form-item>
      </a-col>
      <a-col :md="12" :sm="24">
        <a-form-item label="级别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number
            disabled
            style="width: 100%"
            v-decorator="[
              'rate',
              {rules: [{ type: 'number', required: false, message: '请输入级别', whitespace: true}]}
            ]"/>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="24" :sm="24">
        <a-form-item label="地址" :labelCol="{sm: { span: 24 },md: { span: 3 }}" :wrapperCol="{sm: { span: 24 },md: { span: 21 }}">
          <a-input
            v-decorator="[
              'address',
              {rules: [{ required: false, message: '地址不能为空', whitespace: true}]}
            ]"
            placeholder=""
          />
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-col :md="24" :sm="24">
        <a-form-item label="备注" :labelCol="{sm: { span: 24 },md: { span: 3 }}" :wrapperCol="{sm: { span: 24 },md: { span: 21 }}">
          <a-textarea
            placeholder=""
            :rows="4"
            v-decorator="[
              'remarks',
              {rules: [{ required: false, message: '请输入备注', whitespace: true}]}
            ]"
          />
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="8" :style="{display:'none'}">
      <a-col :md="8" :sm="24">
        <a-form-item label="组织id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input
            v-decorator="[
              'orgId',
              {rules: [{ required: false, message: '请输入组织id', whitespace: true}]}
            ]"
            placeholder=""
          />
        </a-form-item>
      </a-col>
    </a-row>
  </a-form>
</template>

<script>
import { getBatchDict, getOrgTypeTree, getOrgTreeByType, getOrgSelectTree } from "@/services/system/api"
import moment from 'moment'
export default {
  data () {
    return {
      hideChecked: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      confirmLoading: false,
      dictData: {},
      orgTypeSelectTreeData: [],
      areaCodeSelectTreeData: [],
      orgSelectTreeData: [],
      form: this.$form.createForm(this),
      initData: {}
    }
  },
  created () {
    // 数据初始化
    const params = {}
    params.dictFields = 'orgPro'
    this.$http.post(getBatchDict,params).then(res => {
      this.dictData = res.result
    })
    this.$http.post(getOrgTypeTree,{}).then(res => {
      this.orgTypeSelectTreeData = res.result
    })
    this.getOrgTreeByType()
    this.getOrgSelectTree()
  },
  methods: {
    moment,
    getOrgTreeByType () {
      const orgTreeTypeParams = {}
      orgTreeTypeParams.orgType = '0003'
      setTimeout(() => {
        this.$http.post(getOrgTreeByType,orgTreeTypeParams).then(res => {
          this.areaCodeSelectTreeData = res.result
        })
      }, 20)
    },
    getOrgSelectTree () {
      const orgTreeParams = {}
      // 下拉组织树初始化
      setTimeout(() => {
        this.$http.post(getOrgSelectTree,orgTreeParams).then(res => {
          this.orgSelectTreeData = res.result
        })
      }, 20)
    },
    setInitDate (orgInfo) {
      this.form.resetFields()
      if (orgInfo) {
        delete orgInfo.orgTypeName
        delete orgInfo.parentName
        delete orgInfo.parentCode
        delete orgInfo.statusName
        delete orgInfo.fictitiousName
        delete orgInfo.orgProName
        delete orgInfo.treeFlagName
        delete orgInfo.mainDeptName
        delete orgInfo.areaCodeName
        delete orgInfo.insideFlagName
        delete orgInfo.hasAccountName
        delete orgInfo.opRouterId
        delete orgInfo.opOplogId
        delete orgInfo.opFuncId
        delete orgInfo.accessToken
        delete orgInfo.reqIp
        delete orgInfo.pageNum
        delete orgInfo.pageSize
        this.form.setFieldsValue(orgInfo)
      }
    }
  }
}
</script>
